package com.wencai.daily;

import com.wencai.bean.Stock;
import com.wencai.test.WencaiUtils;
import com.wencai.util.ExchangeDay;
import com.wencai.util.ExportUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author wangpan
 * @date 2023/6/11
 */
public class WencaiTest {

    public static String date = "20230117";

    private static String hexinValue =
            "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "A1yiKeUsVKwMYSDw2dE8kN5dLXEL1QKMgnoUzzZcaogqpPIvXuXQj9KJ5EuF";

    static {
        hexinValue = hexinValue.trim();
    }


    public static void main(String[] args) throws IOException, InterruptedException {

        List<List<Stock>> outList = new ArrayList<>();
        String start = date;
        int i = 0;
        try {

            while (date.startsWith("2023")) {
                String str = "主板;非退市;非st;";
                str += fix("首板;");
                str += fix("非一字涨停;");
                str += fix("非T字涨停;");
                str += fix("(成交额/12.5)小于");
                date = ExchangeDay.getNextExchangeDay(date);
                str += fix("竞价成交额;");
                str += fix("竞价涨幅小于7%且大于2%;");
                str += fix("竞价涨幅;");
                System.out.println(str);

                List<Stock> dailyStock = WencaiUtils.getDailyStock(date, str, date, hexinValue);
                outList.add(dailyStock);
                System.out.println(dailyStock);
                Thread.sleep(3000);
            }
        } catch (Exception e) {
            ExportUtils.exportWithSheets(getHead(), outList, Stock.class, "D:\\Users\\Administrator\\Desktop\\python\\" + start + ".xlsx");
        }
    }

    private static List<List<String>> getHead() {
        List<List<String>> head = new ArrayList<>();
        head.add(Collections.singletonList("名称"));
        head.add(Collections.singletonList("代码"));
        head.add(Collections.singletonList("涨幅"));
        head.add(Collections.singletonList("日期"));
        head.add(Collections.singletonList("value"));
        return head;
    }


//    String str = "主板;非st;非退市;";
//    str += fix("涨跌幅小于5%;");
//    str += fix("最高价小于");
//    date = ExchangeDay.getNextExchangeDay(date);
//    str += fix("最高价;");
//    str += fix("振幅大于7%;");
//    str += fix("开盘价小于");
//    str += fix("收盘价*1.015;");
//    str += fix("开盘价大于");
//    str += fix("收盘价*0.985;");
//    str += fix("未涨停;");
//            System.out.println(str);


//    String str = "主板;非st;非退市;";
//    date = ExchangeDay.getNextExchangeDay(date);
//    str += fix("涨幅大于3%;");
//    str += fix("涨幅小于7%;");
//    str += fix("最低价小于5日线;");
//    str += fix("收盘价大于5日线;");
//    str += fix("最低价小于10日线;");
//    str += fix("收盘价大于10日线;");
//    str += fix("均线多头排列;");
//            System.out.println(str);


//    String str = "主板;非st;非退市;";
//    str += fix("未涨停;");
//    date = ExchangeDay.getNextExchangeDay(date);
//    str += fix("9点30分至10点振幅大于7 %;");
//    str += fix("最高价等于涨停价;");
//    str += fix("10点未涨停;");
//    str += fix("10点涨幅大于0%;");
//            System.out.println(str);


    public static String fix(String x) {
        return date.substring(0, 4) + "年" + date.substring(4, 6) + "月" + date.substring(6, 8) + "日" + x;
    }
}
